<?php
/**
 * redis管理工具
 */
namespace app\common\utils;
use think\facade\Cache;

Class RedisUtils
{
    /**
     * 根据key获取msgpack数据并解析为array方式
     *
     * @param  [type] $key [description]
     * @return [type]      [description]
     */
    static public function get($key)
    {
        $msgpack = Cache::get($key);
        return msgpack_unpack($msgpack);
    }

    /**
     * 设置msgpack缓存数据，有效期到下日凌晨之后的30分钟
     *
     * @param [type] $key    [description]
     * @param [type] $array  [description]
     * @param [type] $time   [description]
     */
    static public function set($key, $array)
    {
        $time = strtotime(date('Y-m-d'). ' 23:59:59') - time() + 60*60;
        $msgpack = msgpack_pack($array);
        Cache::set($key, $msgpack, $time);
    }

    /**
     * 设置msgpack缓存数据，有效期5s
     *
     * @param [type] $key    [description]
     * @param [type] $array  [description]
     * @param [type] $time   [description]
     */
    static public function setu($key, $array)
    {
        $msgpack = msgpack_pack($array);
        Cache::set($key, $msgpack, 15);
    }

    /**
     * 移除缓存
     *
     * @param  [type] $key [description]
     * @return [type]      [description]
     */
    static public function rm($key)
    {
        Cache::rm($key);
    }
}
